﻿using System.Windows.Forms;

namespace Связь_с_БД
{
    class InfoStudentExcelToBase
    {
        private readonly DataGridViewRow _dgvr;

        private string[] _documentStudentValue;
        private string[] _examsValue;
        private string[] _jobsValue;
        private string[] _learningDataValue;
        private string[] _learningValue;
        private string[] _learningDataDocumentValue;
        private string[] _parentsValue;
        private string[] _paymentsValue;
        private string[] _previousEducationValue;
        private string[] _privateDataValue;

        public InfoStudentExcelToBase(DataGridViewRow dataGridViewRow)
        {
            _dgvr = dataGridViewRow;
        }

        public string[] GetDocumentStudentValue() 
        {
            return _documentStudentValue; 
        }
        public string[] GetExamsValue()
        {
            return _examsValue; 
        }
        public string[] GetJobsValue()
        {
             return _jobsValue; 
        }
        public string[] GetLearningDataValue()
        {
             return _learningDataValue; 
        }
        public string[] GetLearningValue()
        {
             return _learningValue; 
        }
        public string[] GetLearningDataDocumentValue()
        {
             return _learningDataDocumentValue; 
        }
        public string[] GetParentsValue()
        {
             return _parentsValue; 
        }
        public string[] GetPaymentsValue()
        {
            return _paymentsValue; 
        }
        public string[] GetPreviousEducationValue()
        {
             return _previousEducationValue; 
        }
        public string[] GetPrivateDataValue()
        {
            return _privateDataValue; 
        }

        private void SetDocumentStudentValue()
        {
            _documentStudentValue = new string[10];
            _documentStudentValue[0] = _dgvr.Cells[29].Value.ToString();
            _documentStudentValue[1] = _dgvr.Cells[30].Value.ToString();
            _documentStudentValue[2] = _dgvr.Cells[32].Value.ToString();
            _documentStudentValue[3] = _dgvr.Cells[33].Value.ToString();
            _documentStudentValue[4] = _dgvr.Cells[34].Value.ToString();
            _documentStudentValue[5] = _dgvr.Cells[49].Value.ToString();
            _documentStudentValue[6] = _dgvr.Cells[50].Value.ToString();
            _documentStudentValue[7] = _dgvr.Cells[51].Value.ToString();
            _documentStudentValue[8] = _dgvr.Cells[52].Value.ToString();
            _documentStudentValue[9] = _dgvr.Cells[53].Value.ToString();
        }

        private void SetExamsValue()
        {
            _examsValue = new string[9];
            _examsValue[0] = _dgvr.Cells[63].Value.ToString();
            _examsValue[1] = _dgvr.Cells[64].Value.ToString();
            _examsValue[2] = _dgvr.Cells[65].Value.ToString();
            _examsValue[3] = _dgvr.Cells[66].Value.ToString();
            _examsValue[4] = _dgvr.Cells[67].Value.ToString();
            _examsValue[5] = _dgvr.Cells[69].Value.ToString();
            _examsValue[6] = _dgvr.Cells[70].Value.ToString();
            _examsValue[7] = _dgvr.Cells[72].Value.ToString();
            _examsValue[8] = _dgvr.Cells[71].Value.ToString();
        }

        private void SetJobsValue()
        {
            _jobsValue = new string[6];
            _jobsValue[0] = _dgvr.Cells[19].Value.ToString();
            _jobsValue[1] = _dgvr.Cells[20].Value.ToString();
            _jobsValue[2] = _dgvr.Cells[21].Value.ToString();
            _jobsValue[3] = _dgvr.Cells[48].Value.ToString();
            _jobsValue[4] = _dgvr.Cells[54].Value.ToString();
            _jobsValue[5] = _dgvr.Cells[55].Value.ToString();
        }

        private void SetLearningDataValue()
        {
            _learningDataValue = new string[13];
            _learningDataValue[0] = _dgvr.Cells[2].Value.ToString();
            _learningDataValue[1] = _dgvr.Cells[3].Value.ToString();
            _learningDataValue[2] = _dgvr.Cells[5].Value.ToString();
            _learningDataValue[3] = _dgvr.Cells[4].Value.ToString();
            _learningDataValue[4] = _dgvr.Cells[8].Value.ToString();
            _learningDataValue[5] = _dgvr.Cells[9].Value.ToString();
            _learningDataValue[6] = _dgvr.Cells[23].Value.ToString();
            _learningDataValue[7] = _dgvr.Cells[24].Value.ToString();
            _learningDataValue[8] = _dgvr.Cells[68].Value.ToString();
            _learningDataValue[9] = _dgvr.Cells[1].Value.ToString();
            _learningDataValue[10] = string.Empty;
            _learningDataValue[11] = string.Empty;
            _learningDataValue[12] = _dgvr.Cells[12].Value.ToString();
        }

        private void SetLearningValue()
        {
            _learningValue = new string[9];
            _learningValue[0] = _dgvr.Cells[45].Value.ToString();
            _learningValue[1] = _dgvr.Cells[46].Value.ToString();
            _learningValue[2] = _dgvr.Cells[47].Value.ToString();
            _learningValue[3] = _dgvr.Cells[57].Value.ToString();
            _learningValue[4] = _dgvr.Cells[58].Value.ToString();
            _learningValue[5] = _dgvr.Cells[59].Value.ToString();
            _learningValue[6] = _dgvr.Cells[60].Value.ToString();
            _learningValue[7] = _dgvr.Cells[56].Value.ToString();
            _learningValue[8] = _dgvr.Cells[75].Value.ToString();
        }

        private void SetLearningDataDocumentValue()
        {
            _learningDataDocumentValue = new string[8];
            string str = GetMySqlDateTime(GetYear(_dgvr.Cells[37].Value.ToString()),
                                                 GetMounth(_dgvr.Cells[37].Value.ToString()),
                                                           GetDay(_dgvr.Cells[37].Value.ToString()),
                                                                  GetHours(_dgvr.Cells[37].Value.ToString()),
                                                                           GetMinutes(_dgvr.Cells[37].Value.ToString()),
                                                                                      GetSeconds(
                                                                                          _dgvr.Cells[37].Value.ToString
                                                                                              ()));

            _learningDataDocumentValue[0] = str;
            _learningDataDocumentValue[1] = _dgvr.Cells[42].Value.ToString();
            _learningDataDocumentValue[2] = _dgvr.Cells[43].Value.ToString();
            _learningDataDocumentValue[3] = string.Empty;
            _learningDataDocumentValue[4] = _dgvr.Cells[44].Value.ToString();
            _learningDataDocumentValue[5] = string.Empty;
            _learningDataDocumentValue[6] = string.Empty;
            _learningDataDocumentValue[7] = string.Empty;
        }

        private void SetParentsValue()
        {
            _parentsValue = new string[4];
            _parentsValue[0] = string.Empty;
            _parentsValue[1] = string.Empty;
            _parentsValue[2] = string.Empty;
            _parentsValue[3] = string.Empty;
        }

        private void SetPaymentsValue()
        {
            _paymentsValue = new string[3];
            _paymentsValue[0] = _dgvr.Cells[13].Value.ToString();
            _paymentsValue[1] = _dgvr.Cells[14].Value.ToString();
            _paymentsValue[2] = _dgvr.Cells[15].Value.ToString();
        }

        private void SetPreviousEducationValue()
        {
            _previousEducationValue = new string[9];
            _previousEducationValue[0] = _dgvr.Cells[27].Value.ToString();
            _previousEducationValue[1] = _dgvr.Cells[28].Value.ToString();
            _previousEducationValue[2] = string.Empty;
            _previousEducationValue[3] = _dgvr.Cells[22].Value.ToString();
            _previousEducationValue[4] = _dgvr.Cells[61].Value.ToString();
            string str = GetMySqlDate(GetYear(_dgvr.Cells[35].Value.ToString().Substring(0, 10)),
                                      GetMounth(_dgvr.Cells[35].Value.ToString().Substring(0, 10)),
                                      GetDay(_dgvr.Cells[35].Value.ToString().Substring(0, 10)));
            _previousEducationValue[5] = str;
            _previousEducationValue[6] = _dgvr.Cells[62].Value.ToString();
            _previousEducationValue[7] = string.Empty;
            _previousEducationValue[8] = _dgvr.Cells[36].Value.ToString();
        }

        private void SetPrivateDataValue()
        {
            _privateDataValue = new string[16];
            _privateDataValue[0] = _dgvr.Cells[6].Value.ToString();
            _privateDataValue[1] = _dgvr.Cells[7].Value.ToString();
            _privateDataValue[2] = _dgvr.Cells[11].Value.ToString();
            _privateDataValue[3] = _dgvr.Cells[10].Value.ToString();
            _privateDataValue[4] = _dgvr.Cells[17].Value.ToString();
            _privateDataValue[5] = _dgvr.Cells[16].Value.ToString();
            _privateDataValue[6] = _dgvr.Cells[18].Value.ToString();
            _privateDataValue[7] = _dgvr.Cells[25].Value.ToString();
            string str = GetMySqlDate(GetYear(_dgvr.Cells[26].Value.ToString().Substring(0, 10)),
                                      GetMounth(_dgvr.Cells[26].Value.ToString().Substring(0, 10)),
                                      GetDay(_dgvr.Cells[26].Value.ToString().Substring(0, 10)));
            _privateDataValue[8] = str;
            _privateDataValue[9] = _dgvr.Cells[41].Value.ToString();
            _privateDataValue[10] = _dgvr.Cells[38].Value + _dgvr.Cells[39].Value.ToString();
            _privateDataValue[11] = _dgvr.Cells[40].Value.ToString();
            _privateDataValue[12] = _dgvr.Cells[31].Value.ToString();
            _privateDataValue[13] = string.Empty;
            _privateDataValue[14] = string.Empty;
            _privateDataValue[15] = _dgvr.Cells[73].Value.ToString();
        }

        public void SetAllData()
        {
            SetDocumentStudentValue();
            SetExamsValue();
            SetJobsValue();
            SetLearningDataDocumentValue();
            SetLearningDataValue();
            SetLearningValue();
            SetParentsValue();
            SetPaymentsValue();
            SetPreviousEducationValue();
            SetPrivateDataValue();
        }

        private string GetYear(string str)
        {
            string res = str[6].ToString() + str[7].ToString() + str[8].ToString() + str[9].ToString();
            return res;
        }
        private string GetMounth(string str)
        {
            string res = str[3].ToString() + str[4].ToString();
            return res;
        }
        private string GetDay(string str)
        {
            string res = str[0].ToString() + str[1].ToString();
            return res;
        }
        private string GetHours(string str)
        {
            string res = str[11].ToString() + str[12].ToString();
            return res;
        }
        private string GetMinutes(string str)
        {
            string res = str[14].ToString() + str[15].ToString();
            return res;
        }
        private string GetSeconds(string str)
        {
            string res = str[17].ToString() + str[18].ToString();
            return res;
        }
        private string GetMySqlDateTime(string year,string mounth,string day,string hours,string minutes, string seconds)
        {
            string res = string.Empty;
            res += year;
            res += "-";
            res += mounth;
            res += "-";
            res += day;
            res += " ";
            res += hours;
            res += ":";
            res += minutes;
            res += ":";
            res += seconds;
            return res;
        }
        private string GetMySqlDate(string year, string mounth, string day)
        {
            string res = string.Empty;
            res += year;
            res += "-";
            res += mounth;
            res += "-";
            res += day;
            return res;
        }
    }
}
